package org.rednebula.framework.core.service;

import java.io.Serializable;

import org.rednebula.framework.core.IEnvironment;
import org.rednebula.framework.core.exception.LandException;
import org.rednebula.framework.core.log.Log;
import org.rednebula.framework.core.model.domain.IModel;
import org.rednebula.framework.core.model.form.IForm;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;



@Repository
@Transactional(rollbackFor=LandException.class)
public class DefaultCombineService implements ICombineService, Serializable {

	static Log logger=Log.getLog(DefaultCombineService.class);
	
	public IModel create(IEnvironment envi, IForm form) {
		IModel model=form.getHandlerService().create(envi, form);
		form.getAssembleService().create(envi, form,model);
		model.create(envi);
		form.clearTemporaryData();
		return model;
	}

	public IModel find(IEnvironment envi, IForm form) {
		IModel model=form.getHandlerService().find(envi, form);
		model=form.getAssembleService().find(envi,  form,model);
		form.clearTemporaryData();
		return model;
	}

	public void modify(IEnvironment envi, IForm form) {
		IModel model=form.getHandlerService().modify(envi, form);
		form.getAssembleService().modify(envi, form,model);
		model.modify(envi);
		form.clearTemporaryData();
	}
    
	public 	void delete(IEnvironment envi,IForm form){
		IModel model=form.getHandlerService().modify(envi, form);
		form.getAssembleService().delete(envi, form,model);
		model.delete(envi);
		form.clearTemporaryData();
	}

	public IModel other(IEnvironment envi, IForm form) {
		IModel model=form.getHandlerService().other(envi, form);
		model=form.getAssembleService().other(envi, form,model);
		form.clearTemporaryData();
		return model;
	}
}
